
// ===============================================================================================================
// -*- C++ -*-
//
// Billboard.hpp - Definition of a billboard class.
//
// Copyright (c) 2011 Guilherme R. Lampert
// guilherme.ronaldo.lampert@gmail.com
//
// This code is licenced under the MIT license.
//
// This software is provided "as is" without express or implied
// warranties. You may freely copy and compile this source into
// applications you distribute provided that the copyright text
// above is included in the resulting source code.
//
// ===============================================================================================================

#ifndef __BILLBOARD_HPP__
#define __BILLBOARD_HPP__

// Local includes
#include <Vector.hpp>
#include <Texture.hpp>
#include <Sprite.hpp>

///
/// Billboard -- A 3D textured quad that always face the camera.
/// It can also contain an animated sprite.
///
class Billboard : public ReferenceCountable {

	friend class Renderer;

public:

	// Public Interface:

	/// Creates a new instance of the MemoryBuffer class.
	static Billboard * Create(const Sprite * anim, float distForAnimPlayback, float sizeFactor, const Vec3 & position);

	// Data Access:

	void SetSprite(const Sprite * s);
	const Sprite * GetSprite(void) const;

	void SetDistForAnimPlayback(float dist);
	float GetDistForAnimPlayback(void) const;

	// ReferenceCountable Methods:

	virtual unsigned long AddRef(void) const;
	virtual unsigned long Release(void) const;
	virtual unsigned long ReferenceCount(void) const;

protected:

	virtual ~Billboard(void);

private:

	// This will prevent the class from being staticaly allocated.
	// The only way to create an instance of it now is thru the Billboard::Create() method.
	explicit Billboard(const Sprite * anim, float distForAnimPlayback, float sizeFactor, const Vec3 & position);

	// Disable copy.
	Billboard(const Billboard &);
	Billboard & operator = (const Billboard &);

private:

	// Member Variables:

	const Sprite * sprite;
	GLuint textureID;

	float distForAnimToPlay; // How far from the camera it must be to animate
	float size;
	Vec3 pos;
};

///
/// Reference countable billboard pointer type.
///
typedef RefPtr<Billboard> BillboardPtr;

#endif // __BILLBOARD_HPP__